Repository navigation
Conversation
|
Hi @adeelejaz! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
-[RCTComponentViewFactory _registerComponentIfPossible:]runs on the JS thread, from theComponentDescriptorProviderRegistryrequest callback. Its legacy-interop fallback and itsUnimplementedViewfallback write_componentViewClassesand_registrationStatusMapwithout taking_mutex. Its early_registrationStatusMap.findand-_wasComponentRegistered:also read without the lock.On the main thread,
-createComponentViewWithComponentHandle:takes onlystd::shared_lock lock(_mutex)before it calls_componentViewClasses.find(handle). So an unlocked insert, particularly one that rehashes the map, can make that lookup miss a handle registered long ago. In practice the missed handle is often the built-inParagraph:RCTAssert: ComponentView with componentHandle … (Paragraph) not found.0x18.Any app that renders a component through the legacy interop layer is exposed: a library without Fabric codegen,
RNCMaskedView, or any host name that resolves toUnimplementedView. The first render of each such name is a writer.This PR takes the factory lock only around the map reads and writes:
std::shared_lockin-_wasComponentRegistered:and around the early status-map check._providerRegistry.add(provider)is called with no factory lock held. Thenstd::unique_lockis taken for the two map writes only.The ordering is safe.
_registerComponentIfPossible:runs synchronously insideComponentDescriptorRegistry::aton the JS thread, and returns only after the writes, so the new name cannot be used before the maps hold it. Upstream already adds the provider before writing the maps.The lock deliberately does not span
_providerRegistry.add, unlike the fix proposed in #58299. Building aLegacyViewManagerInteropComponentDescriptorcan lazily load a view manager that requires main-queue setup (RCTUnsafeExecuteOnMainQueueSync; see #53128). Holding the factory lock across that would deadlock against a main thread waiting for the lock in-createComponentViewWithComponentHandle:. With this change, nothing but map operations runs under the lock.Fixes #60244 (re-files #58299) (closed by the bot for lack of a reproducer; the race is still present on
main).Changelog:
[IOS] [FIXED] - Fix a data race in
RCTComponentViewFactorywhere legacy-interop and Unimplemented component registration wrote the component registry without its lock, which could crash view creation ("ComponentView … (Paragraph) not found").Test Plan:
ThreadSanitizer, before and after. Setup:
-fsanitize=threadadded as a per-file compiler flag onRCTComponentViewFactory.mm, plus the link flag.<Text>on alternate frames, more than the 1,024-view recycle pool, so the main thread keeps creating views;nativeFabricUIManager.createNode(tag, "Probe" + n, rootTag, {}, {})). Each one forces anUnimplementedViewfallback registration.Without this change, TSan reports:
With this change, the same build, harness and run report no data race.
Also run: the app's full Jest suite and its iOS end-to-end flows on the patched source build.
The stress harness drives only the
UnimplementedViewfallback, because fresh legacy view-manager names can't be minted at runtime. The legacy-interop fallback gets the same lock shape, and is covered by code reading rather than by a TSan run.Also unlocked but not changed here:
+[RCTLegacyViewManagerInteropComponentView isSupported:]writes a staticNSMutableDictionary. Its only caller is the legacy-interop fallback, on the JS thread.